#include<stdio.h>
#include<memory.h>

#include<unistd.h>
#include<string.h>
#include <fcntl.h>
#include <sys/stat.h>

int main(){
 /* FILE* f1 = fopen("bite","w+");//w只有读权限
  const char * write_string="linux easy easy";
  fwrite(write_string,strlen(write_string)+1,1,f1);
  char read_string[20];//这个stream f1 的file position diciator的已经指向结尾，现在要从头读
  fseek(f1,0,SEEK_SET);
  fread(read_string,15,1,f1);
  printf("%s\n",read_string);
  fclose(f1);*/
  //打开文件指针，然后利用fseek，
  
  umask(0);
  int fd=open("./bite",O_CREAT|O_RDWR,0664);
  if(fd<0){
    perror("open error");
    return -1;
  }
  char * data="i like linux!\n";
  ssize_t ret=write(fd,data,strlen(data));
  if(ret<0){
    perror("write error");
    return -1;
  }
  
  lseek(fd,0,SEEK_SET);
  char buf[1024]={0};
  ret=read(fd,buf,1024);
  if(ret<0){
    perror("read error");
    return -1;
  }else if(ret==0){
    printf("end of file!\n");
  }
  printf("%s\n",buf);
  close(fd);
  return 0;

}
